<?php

declare (strict_types=1);

namespace App\Model;

use App\Utils\Upload\View;
use Hyperf\DbConnection\Model\Model;

/**
 * Class TaskStep
 * @package App\Model
 * @property mixed|int id
 * @property mixed|int task_id
 * @property mixed|int step_type
 * @property mixed|string text
 * @property mixed|string image
 * @property mixed|string created_at
 * @property mixed|string updated_at
 */
class TaskStep extends Model
{
    protected $table = 'task_step';

    public function getImageAttribute($value)
    {
        if ($value) {
            $images = explode('|', $value);
            if (count($images) > 1) {
                $imagesRender = [];
                $viewClass = di(View::class);
                foreach ($images as $v) {
                    if ($v){
                        $imagesRender[] = [
                            'image_id' => $v,
                            'image_path' => $viewClass->fullPath($v)
                        ];
                    }
                }
                return $imagesRender;
            } else {
                return [
                    'image_id' => $value,
                    'image_path' => di(View::class)->fullPath($value)
                ];
            }
        } else {
            return '';
        }
    }
}